package com.ymatou.iapi.godproductsearch.testcase;

import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.noggit.JSONParser;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.service.AddAgentProductCall;
import com.shop2cn.iapi.agentproducts.service.ImportAgentProductCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godproductsearch.parameter.searchBean;
import com.ymatou.iapi.godproductsearch.service.searchCall;
import com.ymatou.iapi.productsynces.parameter.ESBean;
import com.ymatou.iapi.productsynces.service.ESCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.YmtCatalogs;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.sqlwapper.YmtCatalogsWapper;
import com.ymttest.database.sqlwapper.YmtProductCategoryWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsWapper;
import com.ymttest.utils.TestDataManager;
/**
*商品搜索
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_search{
	private static searchBean bean;
	private static searchCall call;
	private  AddAgentProductCall addagentproductCall=new AddAgentProductCall();
	private ImportAgentProductCall importagentproductCall=new ImportAgentProductCall();
	private YmtProductsIWapper YmtProductsIWapper =new YmtProductsIWapper();
	private YmtProductCategoryWapper ymtProductCategoryWapper=new YmtProductCategoryWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品搜索");
	}

	@Before
	public void caseUp() {
		bean=new searchBean();
		call=new searchCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_001() {
		Logger.start(true,"正例-商品搜索-根据一级分类查询");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(5000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，es数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_001_1() {
		Logger.start(true,"正例-商品搜索-根据二级分类查询");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(5000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSecondCategoryId(Integer.parseInt(category2.get("iCategoryId").toString()));
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，es数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_001_2() {
		Logger.start(true,"正例-商品搜索-根据二级分类查询-二级分类不存在");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(5000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSecondCategoryId(Integer.parseInt(category2.get("iCategoryId").toString())+1);//不存在的二级分类
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，es数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(0, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(0, call.getProductDtos().length(), "验证productDtos为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_002() {
		Logger.start(true,"正例-商品搜索-同一个用户创建两个商品，title含有相同的词");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();//初始化创建用户 为什么手机号没有值
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.setTitle("中国人民好");
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2			
			addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.setTitle("中国好");
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(5000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle("中国");
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，es数据库默认的
            bean.setSortMode(1);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_003() {
		Logger.start(true,"正例-商品搜索-同一个用户创建两个商品，含有一个商品对应的title,返回显示一条数据");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();//初始化创建用户 为什么手机号没有值
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.setTitle("小明");
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2			
			addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.setTitle("红儿");
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(5000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle("小明");
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，es数据库默认的
            bean.setSortMode(1);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(1, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
//			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_004() {
		Logger.start(true,"正例-商品搜索-按价格升序-sortField=2 sortMode=1,换算前 商品1(人名币)的价格小于商品2(美元)");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(2d);
			addAgentProductBean.setCurrency("CNY");
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(3d);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(10000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(1);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_004_1() {
		Logger.start(true,"正例-商品搜索-按价格升序-sortField=2 sortMode=1,换算前 商品1(人名币)的价格大于商品2(美元)");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(2d);
			addAgentProductBean.setCurrency("CNY");
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(1d);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(10000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(1);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_005() {
		Logger.start(true,"正例-商品搜索-按价格降序-sortField=2 sortMode=2");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(2d);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(3d);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(10000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			Logger.verifyEquals(product1, new JSONObject(call.getProductDtos().get(1).toString()).get("productId"), "验证第二个商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_006() {
		Logger.start(true,"正例-商品搜索-pageSize 大于商品总条数");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(2d);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(3d);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			Thread.sleep(2000);
			Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(1);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(1);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(2, call.getRecordCount(), "验证返回的RecordCount等于2");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_007() {
		Logger.start(true,"正例-商品搜索-sellerId为空");
		try {
			bean.setTitle("God");
            //bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(1001);
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();				
			//校验
			Logger.verifyEquals("false", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals("1", call.getErrorCode(), "验证返回的ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_008() {
		Logger.start(true,"正例-商品搜索-sortField为空");
		try {
			bean.setTitle("God");
            bean.setSellerId(3382);
            bean.setFirstCategoryId(1001);
           // bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("false", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals("1", call.getErrorCode(), "验证返回的ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_009() {
		Logger.start(true,"正例-商品搜索-sortMode为空");
		try {
			bean.setTitle("God");
            bean.setSellerId(3382);
            bean.setFirstCategoryId(1001);
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            //bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("false", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals("1", call.getErrorCode(), "验证返回的ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_010() {
		Logger.start(true,"正例-商品搜索-pageIndex为空");
		try {
			bean.setTitle("God");
            bean.setSellerId(3382);
            bean.setFirstCategoryId(1001);
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            //bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();					
			//校验
			Logger.verifyEquals("false", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals("1", call.getErrorCode(), "验证返回的ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_011() {
		Logger.start(true,"正例-商品搜索-pageSize为空");
		try {
			bean.setTitle("God");
            bean.setSellerId(3382);
            bean.setFirstCategoryId(1001);
            bean.setSortField(2);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，bes数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
           // bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("false", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals("1", call.getErrorCode(), "验证返回的ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_search_012() {
		Logger.start(true,"正例-商品搜索-已售罄的商品不显示");
		try {
			//创建商户 渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			//创建商品1
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,usercreateBean1.getNickname(),false);
			addAgentProductBean.getCatalogList().remove(0);
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product1 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Thread.sleep(2000);
			//商品2
			addagentproductCall.setData(addAgentProductBean);
			addagentproductCall.callService();
			String product2 = addagentproductCall.getJsonObject().get("data").getAsJsonObject().get("newProductId").getAsString();
			Logger.comment("###  product1  ###  "+product1);
			Logger.comment("###  product2  ###  "+product2);
			//修改商品已售罄
			Logger.comment("############## 修改库存为0并同步开始 ################");
			 YmtCatalogsWapper catalogdWapper=new YmtCatalogsWapper();
			 YmtProductsWapper productMapper=new YmtProductsWapper();
		     YmtCatalogs catalogs=catalogdWapper.selectBySproductId(product1);
			//修改 
			 catalogs.setInum(0);
			 int count1=catalogdWapper.updateByPrimaryKey(catalogs);
			 //同步已售罄
			 ESBean esBean=new ESBean();
			 ESCall escall=new ESCall();
			 esBean.setActionType("SyncAgentProductStockStatus");
			 esBean.setActivityId(0);
			 esBean.setProductId(product1);
			 esBean.setTransactionId(TestDataManager.getRandomIntNum(10));
			 escall.setData(esBean);
			 escall.callService();
			 Thread.sleep(5000);
			 Logger.comment("############## 修改库存为0并同步结束 ################");
			 Logger.comment("#### 查询一级分类  ###");
			//找一级分类
			YmtProductsI YmtProductsI=YmtProductsIWapper.selectProductByProductId(product1).get(0);
			//二级
			Map category2= ymtProductCategoryWapper.getProductCategoryByCategoryId(YmtProductsI.getiCategoryId()).get(0);
			//es查询
            bean.setTitle(addAgentProductBean.getTitle());
            bean.setSellerId(userId_channl);
            bean.setFirstCategoryId(Integer.parseInt(category2.get("iMasterCategory").toString()));
            bean.setSortField(1);//排序字段Default-1 Price-2 如果是Default默认，则不根据SortMode排序，es数据库默认的
            bean.setSortMode(2);//排序方式ASC-1 DESC-2   默认时根据utime 排序
            bean.setPageIndex(1);
            bean.setPageSize(2);
            bean.setappId("es搜索_"+TestDataManager.getRandomIntNum(10));
			call.setData(bean);
			call.callService();			
			//校验
			Logger.verifyEquals("true", call.getSuccess(), "验证返回的success");
			Logger.verifyEquals(1, call.getRecordCount(), "验证返回的RecordCount");
			Logger.verifyEquals(product2, new JSONObject(call.getProductDtos().get(0).toString()).get("productId"), "验证第一个商品");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}